<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dangnhap extends CI_Controller {
    private $tb_setting='setting';
    private $tb_users= 'users'; 
    
    function __construct()
	{
		parent::__construct(); 
		$this->load->helper(array('form','url'));
		$this->load->model('Admin_model');
        $this->load->library(array('session','form_validation','security'));       
    
	}
    
	public function index(){ 
	   $this->form_validation->set_rules('username', 'Tên đăng nhập', 'trim|required|xss_clean');
       $this->form_validation->set_rules('password', 'Mật khẩu', 'trim|required|xss_clean');      
       if ($this->form_validation->run() == TRUE){
            $username = $this->security->xss_clean($_POST['username']);
            $password = $this->security->xss_clean($_POST['password']);
            $password = sha1(md5($password));
            $log = $this ->Admin_model->get_one($this->tb_users,array('username'=>$username,'password'=>$password));
            $num = $this ->Admin_model->get_number($this->tb_users,array('username'=>$username,'password'=>$password));
             //get_number            
            if($num==1){
               $this->session->set_userdata('logedin',1);
               $this->session->set_userdata('id',$log->id);
               $this->session->set_userdata('quyenhan',$log->email);
               $this->session->set_userdata('taikhoan',$log->taikhoan);
               redirect('admin');
            }else{
                $this->session->set_userdata('loidn','Tên đăng nhập hoặc mật khẩu không đúng');
            }
       }
                
       $data['setting'] = $this->Admin_model->get_one($this->tb_setting);
       $data['page'] = $this->load->view('admin/content/login','',true);        
       $this->load->view('admin/index',$data); 
        
        
	}
    
    
    
    
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */